package company.managedbean;

import javax.ejb.EJB;
import company.entity.Company;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;
import java.util.List;
import company.session.stateless.CompanySessionBean;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@ViewScoped
public class DeleteCompanyManagedBean implements Serializable{
  
   public Long id;  
    @EJB
    CompanySessionBean companySessionBean;
    private Company selectedCompany;
     private boolean editMode;  

    public DeleteCompanyManagedBean() {
        selectedCompany=new Company();
    }
    
    public Company getSelectedCompany() {  
        
        return selectedCompany;  
    }  
    public void setSelectedCompany(Company selectedCompany) {  
        this.selectedCompany = selectedCompany;  
    } 
    
    public boolean isEditMode() {  
        return editMode;  
    }  
  
    public void setEditMode(boolean editMode) {  
        this.editMode = editMode;  
    }  

    public List<Company> getCompanies() {
        return companySessionBean.getAllCompanies();
    }

    public void deleteCompany(ActionEvent event) {
       id=(Long)event.getComponent().getAttributes().get("param1");
       companySessionBean.deleteCompany(id);
    }
       
       public void saveChanges(ActionEvent event)
    {
        
        companySessionBean.saveChanges(selectedCompany);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Changes saved.", ""));        
    }

       
    
}
